﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PreeRegisterModel;
using System.Data;
using PreeRegisterDAL;

namespace PreeRegisterBLL
{
    public class CheckReportBLL
    {
        /// <summary>
        /// 体检报告列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static CheckReportListResponseModel GetCheckReportList(CheckReportListRequestModel request)
        {
            try
            {
                //查询体检报告列表
                CheckReportListResponseModel CheckReportListResponseModel = new PreeRegisterModel.CheckReportListResponseModel();


                DataSet ds = CheckReportDAL.Getcheckreport(request);

                if (ds == null)
                    return null;

                //获取体检报告列表
                List<CheckReportListItemResponseModel> CheckReportListItemResponseModel_list = new List<CheckReportListItemResponseModel>();

                foreach (DataRow drPacsReport in ds.Tables[0].Rows)
                {
                    CheckReportListItemResponseModel CheckReportListItemResponseModel = new CheckReportListItemResponseModel();
                    CheckReportListItemResponseModel.checkcode = drPacsReport["checkcode"].ToString();
                    CheckReportListItemResponseModel.icheckgroupno = drPacsReport["iCheckGroupNo"].ToString();
                    CheckReportListItemResponseModel.cdeptnode = drPacsReport["cDeptNode"].ToString();
                    CheckReportListItemResponseModel.cdoctorname = drPacsReport["cName"].ToString();
                    CheckReportListItemResponseModel.cgroupname = drPacsReport["cGroupName"].ToString();
                    CheckReportListItemResponseModel.dbodycheckdate = drPacsReport["dBodyCheckDate"].ToString();
                    CheckReportListItemResponseModel.ienrolapplyno = drPacsReport["iEnrolApplyNo"].ToString();

                    CheckReportListItemResponseModel_list.Add(CheckReportListItemResponseModel);
                }

                CheckReportListResponseModel.reportlist = CheckReportListItemResponseModel_list;

                //返回
                return CheckReportListResponseModel;
            }
            catch (Exception err)
            {

                throw;
            }
        }

        /// <summary>
        /// 体检报告明细
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static CheckReportDetailResponseModel GetCheckReportDetail(CheckReportDetailRequestModel request)
        {
            try
            {
                //查询体检报告明细
                CheckReportDetailResponseModel CheckReportDetailResponseModel = new CheckReportDetailResponseModel();

                DataSet ds = CheckReportDAL.GetCheckReportList(request.ienrolapplyno);

                if (ds == null)
                {
                    return null;
                }

                //获取体检报告结果



                CheckReportDetailResponseModel.ienrolapplyno = ds.Tables[0].Rows[0]["iEnrolApplyNo"].ToString();
                CheckReportDetailResponseModel.cgroupname = ds.Tables[0].Rows[0]["cGroupName"].ToString();
                CheckReportDetailResponseModel.icheckgroupno = ds.Tables[0].Rows[0]["iCheckGroupNo"].ToString();

                List<CheckReportDetailItemResponseModel> PacsReportDetailItemResponseModel_list = new List<CheckReportDetailItemResponseModel>();

               foreach (DataRow drPacsReport in ds.Tables[1].Rows)
                {
                    CheckReportDetailItemResponseModel CheckReportDetailItemResponseModel = new CheckReportDetailItemResponseModel();
                    CheckReportDetailItemResponseModel.cbount = drPacsReport["cBount"].ToString();
                    CheckReportDetailItemResponseModel.ccheckitemname = drPacsReport["cCheckItemName"].ToString();
                    CheckReportDetailItemResponseModel.cresult = drPacsReport["cResult"].ToString();
                    CheckReportDetailItemResponseModel.cresultflag = drPacsReport["cResultFlag"].ToString();
                    CheckReportDetailItemResponseModel.cunit = drPacsReport["cUnit"].ToString();
                    CheckReportDetailItemResponseModel.icheckitemno = drPacsReport["iCheckItemNo"].ToString();

                    PacsReportDetailItemResponseModel_list.Add(CheckReportDetailItemResponseModel);
                }



               CheckReportDetailResponseModel.detail = PacsReportDetailItemResponseModel_list;

                //返回
               return CheckReportDetailResponseModel;
            }
            catch (Exception err)
            {

                throw;
            }
        }

        /// <summary>
        /// 体检综检建议
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static CheckAdvicesDetailResponseModel GetCheckAdvicesDetail(CheckAdvicesListRequestModel request)
        {
            try
            {
                //查询体检综检建议
                CheckAdvicesDetailResponseModel CheckAdvicesDetailResponseModel = new CheckAdvicesDetailResponseModel();

                DataSet ds = CheckReportDAL.Getcheckadvices(request);

                if (ds == null)
                {
                    return null;
                }




                CheckAdvicesDetailResponseModel.cdoctorname = ds.Tables[0].Rows[0]["AppraiseOp"].ToString();
                CheckAdvicesDetailResponseModel.checkcode = ds.Tables[0].Rows[0]["cCheckCode"].ToString();
                CheckAdvicesDetailResponseModel.cpatientname = ds.Tables[0].Rows[0]["cPatName"].ToString();
                CheckAdvicesDetailResponseModel.ctel = ds.Tables[0].Rows[0]["cTel"].ToString();
                CheckAdvicesDetailResponseModel.cworkunit = ds.Tables[0].Rows[0]["cWorkUnit"].ToString();
                CheckAdvicesDetailResponseModel.dadvicedate = ds.Tables[0].Rows[0]["dAppraiseDate"].ToString();

                List<CheckAdvicesDetailItemResponseModel> CheckAdvicesDetailItemResponseModel_list = new List<CheckAdvicesDetailItemResponseModel>();

                foreach (DataRow drPacsReport in ds.Tables[1].Rows)
                {
                    CheckAdvicesDetailItemResponseModel CheckAdvicesDetailItemResponseModel = new CheckAdvicesDetailItemResponseModel();
                    CheckAdvicesDetailItemResponseModel.cadvices = drPacsReport["cAdvice"].ToString();
                    CheckAdvicesDetailItemResponseModel.cdiag = drPacsReport["cDiag"].ToString();

                    CheckAdvicesDetailItemResponseModel_list.Add(CheckAdvicesDetailItemResponseModel);
                }



                CheckAdvicesDetailResponseModel.detail = CheckAdvicesDetailItemResponseModel_list;

                //返回
                return CheckAdvicesDetailResponseModel;
            }
            catch (Exception err)
            {

                throw;
            }
        }
    }
}
